package com.sjq.common.web;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sjq.common.entity.Role;
import com.sjq.common.service.AuthorizedService;
import com.sjq.common.service.RoleService;
import com.sjq.common.util.PageResults;

@Controller
@RequestMapping(value="/authorized")
public class AuthorizedController {
	
	@Resource
	private RoleService roleService;
	@Resource
	private AuthorizedService authorizedService;
	//初始化
    @RequestMapping(value="/roleAll")
    public ModelAndView init(Integer pageNo, Integer pageSize, Role role){
    	if(role==null){
    		role=new Role();
    	}
    	pageNo = pageNo == null ? 1 : pageNo;
        PageResults<?> pageResults=roleService.findRoleByPage(pageNo, PageResults.ALLPAGESIZE, role);
    	ModelAndView mav = new ModelAndView();
        mav.setViewName("/view/menu/roleList");
        mav.addObject("allRole", pageResults.getResults());
        mav.addObject("pageNo", pageResults.getPageNo());
        mav.addObject("pages", pageResults.getPageCount());
        return mav;
    }
    
    @RequestMapping(value="/authorizedVeiw")
    public ModelAndView authorizedVeiw(String jsid,String xtid){
    	ModelAndView mav = new ModelAndView();
        mav.setViewName("/view/menu/roleAuthorized");
    	mav.addObject("jsid", jsid);
    	
    	return mav;
    }
    @RequestMapping(value="/selectAuthorized")
    @ResponseBody
    public String authorizedRole(String jsid){
    	String json = authorizedService.selectYSQ(jsid);
    	return json;
    }
    
    @RequestMapping(value="/saveAuthorized")
    @ResponseBody
    public String saveAuthorized(String jsid,String nodes,HttpServletRequest request){
		String json = authorizedService.saveAuthorized(jsid, nodes,request);
    	return json;
    }
}
